package com.yusheng.tr.multi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yusheng.domain.R;
import com.yusheng.tr.common.core.model.dto.multi.TransDistDTO;
import com.yusheng.tr.common.log.annotation.Log;
import com.yusheng.tr.common.log.enums.BusinessType;
import com.yusheng.tr.common.core.entity.multi.TransDistEntity;
import com.yusheng.tr.multi.service.ITransDistService;
import com.yusheng.tr.common.core.model.vo.multi.DistinctAreaVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 运输距离管理功能
 * </p>
 *
 * @author author
 * @since 2023-09-27
 */
@RestController
@RequestMapping("/trans-dist")
@Tag(name = "运输距离管理功能")
public class TransDistController {

    @Autowired
    private ITransDistService transDistService;

    @Log(title = "查询运输距离列表数据", businessType = BusinessType.OTHER)
    @GetMapping("/list")
    @Operation(summary = "查询运输距离列表数据", description = "查询运输距离列表数据")
    @Parameter(name = "params", description = "查询运输距离的实体参数")
    public R<List<TransDistEntity>> queryTransDistList(TransDistEntity params) {
        return R.ok(transDistService.queryTransDistList(params));
    }

    @Log(title = "分页查询运输距离列表数据", businessType = BusinessType.OTHER)
    @Operation(summary = "分页查询运输距离列表数据", description = "分页查询运输距离列表数据")
    @Parameters({
            @Parameter(name = "current", description = "当前页码", required = true),
            @Parameter(name = "size", description = "每页数据量", required = true),
            @Parameter(name = "startArea", description = "根据始发地查询", required = false),
            @Parameter(name = "endArea", description = "根据目的地查询", required = false)
    })
    @GetMapping("/page/list")
    public R<IPage<TransDistEntity>> queryPageTransDistList(Integer current, Integer size, String startArea, String endArea) {

        return R.ok(transDistService.queryPageTransDistList(current, size, startArea, endArea));
    }

    @Log(title = "新增运输数据", businessType = BusinessType.INSERT)
    @Operation(summary = "新增运输数据", description = "新增运输数据")
    @PostMapping("/insert")
    @Parameter(name = "transDistDTO", description = "新增实体参数")
    public R insert(@RequestBody TransDistDTO transDistDTO) {
        transDistService.insert(transDistDTO);
        return R.ok();
    }

    @Log(title = "删除运输数据", businessType = BusinessType.DELETE)
    @Operation(summary = "删除运输数据", description = "删除运输数据")
    @Parameter(name = "id", description = "要删除的id", required = true)
    @DeleteMapping("/delete")
    public R deleteById(String id) {
        transDistService.removeById(id);
        return R.ok();
    }

    @Log(title = "更新运输数据", businessType = BusinessType.UPDATE)
    @Operation(summary = "更新运输数据", description = "更新运输数据")
    @PutMapping("/update")
    @Parameter(name = "transDistDTO", description = "更新数据的实体参数")
    public R updateData(@RequestBody TransDistDTO transDistDTO) {
        transDistService.updateData(transDistDTO);
        return R.ok();
    }


    @Log(title = "对开始区域、到达区域，做去重数据列表查询", businessType = BusinessType.OTHER)
    @Operation(summary = "对开始区域、到达区域，做去重数据列表查询", description = "对开始区域、到达区域，做去重数据列表查询")
    @GetMapping("/select")
    public R<DistinctAreaVO> distinctArea() {

        return R.ok(transDistService.distinctArea());
    }

    @Log(title = "对始发地，目的地进行查询", businessType = BusinessType.OTHER)
    @Operation(summary = "对始发地，目的地进行查询", description = "对始发地，目的地进行查询")
    @Parameters({
            @Parameter(name = "startarea", description = "始发地", required = true),
            @Parameter(name = "endArea", description = "目的地", required = true)
    })
    @GetMapping("/query")
    public R<TransDistEntity> queryArea(String startArea, String endArea) {
        return R.ok(transDistService.queryArea(startArea, endArea));
    }
}
